package com.atguigu.gmall.user.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.common.util.AuthContextHolder;
import com.atguigu.gmall.model.user.UserAddress;
import com.atguigu.gmall.user.service.UserAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * ClassName: UserApiContrller
 * Package: com.atguigu.gmall.user.controller
 * Description:
 *
 * @Author 刘轩
 * @Create 2023-09-01 22:28
 * @Version 1.0
 */

@RestController
@RequestMapping("/api/user/userAddress")
public class UserApiContrller {

 //  注入服务层
 @Autowired
 private UserAddressService userAddressService;

 //  移动端获取收货地址列表.
 //  http://localhost/api/user/userAddress/auth/findUserAddressList
 @GetMapping("/auth/findUserAddressList")
 public Result findUserAddressList(HttpServletRequest request){
  // 获取 id
  String userId = AuthContextHolder.getUserId(request);
  //  需要获取到收货地址列表.
  //  调用服务层方法
  List<UserAddress> userAddressList = userAddressService.findUserAddressList(userId);
  return Result.ok(userAddressList);
 }
}
